package com.boot.web.controller;

import java.util.Map;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.boot.communal.paging.InitPaging;
import com.boot.communal.response.ResponseServer;
import com.boot.web.dto.LoginDTO;
import com.boot.web.dto.UserDTO;
import com.boot.web.service.UserService;

/**
 * 系统用户信息控制器
 * @author 【zhouJie】
 * @date 2019-12-05 17:31:35
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/save")
    public ResponseServer save(UserDTO userDTO) {
        return ResponseServer.success("添加成功", userService.saveUser(userDTO));
    }

    @PutMapping("/update")
    public ResponseServer update(UserDTO userDTO) {
        return ResponseServer.success("修改成功", userService.updateUser(userDTO));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseServer delete(@PathVariable Integer id) {
        return ResponseServer.success("删除成功", userService.deleteUser(id));
    }

    @DeleteMapping("/batchDelete/{ids}")
    public ResponseServer batchDelete(@PathVariable Integer[] ids) {
        return ResponseServer.success("批量删除成功", userService.batchDeleteUser(ids));
    }

    @GetMapping("/getPageList")
    public ResponseServer getPageList(@RequestParam Map<String, Object> params) {
        InitPaging.init(params);
        return ResponseServer.success(new PageInfo(userService.getUserVOPageList(params)));
    }

    @GetMapping("/getAll")
    public ResponseServer getAll() {
        return ResponseServer.success(userService.getAll());
    }

    @GetMapping("/getById/{id}")
    public ResponseServer getById(@PathVariable Integer id) {
        return ResponseServer.success(userService.getById(id));
    }

    @PostMapping("/login")
    public ResponseServer login(LoginDTO loginDTO) {
        return ResponseServer.success("登录成功", userService.login(loginDTO));
    }

    @GetMapping("/getMenuPowerList/{id}")
    public ResponseServer getMenuPowerList(@PathVariable("id") Integer id) {
        return ResponseServer.success(userService.getMenuPowerList(id));
    }

    @PostMapping("/unlock")
    public ResponseServer unLock(@RequestParam String password, String pwd) {
        return ResponseServer.success("解锁成功", userService.unLock(password, pwd));
    }

    @PostMapping("/enableOrDisable/{id}")
    public ResponseServer enableOrDisableUser(@PathVariable Integer id) {
        return ResponseServer.success("修改成功", userService.enableOrDisableUser(id));
    }

}
